function img_average = generate_average_scans_toolbox(patient);
    
    %%Calculate average image, simple;
    
    %| Load all deformed images registered by Elastix to the reference image
    %| geometry, and average them;
    
    %------------------------------------------------------------------------
    %|      Dependancies;
    %|
    %|
    %|
    %------------------------------------------------------------------------
    %   This file is part of the
    %   5D-Novel4DCT Toolbox  ("Novel4DCT-Toolbox")
    %   DH Thomas, Ph.D
    %   University of California, Los Angeles
    %   Contact: mailto:dhthomas@mednet.ucla.edu
    %------------------------------------------------------------------------
    % $Author: DHThomas $	$Date: 2014/04/01 10:23:59 $	$Revision: 0.1 $
    
    if exist([patient.folder '/img_average.mat'])>0
        display('Average Image exists - loading...')
        load([patient.folder '/img_average.mat'])
    else
        
        img_average_lung=zeros(patient.dim);
        
        for scan=1:patient.scans
            display(sprintf('Generating Average Image: Reading Scan %d of %d',scan, patient.scans))
            image_scan_folder = [patient.folder_elastix sprintf('/out_phase1_phase%d',scan)];
            img_tmp=double(metaImageRead([image_scan_folder '/result.1']));
            img_average_lung=(img_average_lung+img_tmp);
        end
        
        img_average=img_average_lung/patient.scans;
        save([patient.folder '/img_average'], 'img_average')
        
        
    end